<?php require_once('common.php');
if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Site extends Common {
	function __construct() {
		parent::__construct("site");

		$this->meta 			= array();
		$this->scripts 			= array();
		$this->styles 			= array();
		$this->title 			= "Welcome";
	}

	public function index(){
		//$this->load->model('user');
		//echo $this->user->get_hash('kasir1','kasir1');die;
		if(!$this->is_logged_in){
			redirect(base_url()."index.php/site/login");
		}else{
			switch($this->user_data['role']){
				case ROLE_PELAYAN :
					redirect(base_url()."index.php/pelayan");
				break;
				
				case ROLE_KOKI :
					redirect(base_url()."index.php/koki");
				break;
				
				case ROLE_KASIR :
					redirect(base_url()."index.php/kasir");
				break;
				
				case ROLE_PANTRY :
					redirect(base_url()."index.php/pantry");
				break;
				
				case ROLE_CS :
					redirect(base_url()."index.php/cs");
				break;
				
				case ROLE_ADMIN :
					redirect(base_url()."index.php/admin");
				break;
			}
		}
	}
	
	public function login(){
		$data['flashdata'] = $this->session->flashdata('form_msg');
		$this->load->view('site/login', $data);
	}
	
	public function login_process(){
		$username = $this->input->post('username');
		$password = $this->input->post('password');
		
		if (isset($username) && isset($password)) {
			if (!$this->user_session->create($username, $password)) {
				$this->session->set_flashdata('form_msg', array('success' => false, 'msg' => 'Login gagal. Username atau password anda salah.'));
				redirect(base_url()."index.php/site/login");
			}else{
				redirect(base_url());
			}
		}
	}
	
	public function logout(){
		$this->user_session->clear();
		redirect(site_url());
	}

}